package com.yy.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.yy.common.annotation.Log;
import com.yy.common.core.controller.BaseController;
import com.yy.common.core.domain.AjaxResult;
import com.yy.common.core.page.TableDataInfo;
import com.yy.common.enums.BusinessType;
import com.yy.common.utils.poi.ExcelUtil;
import com.yy.domain.PayPrestore;
import com.yy.domain.PayPrestoreAccount;
import com.yy.service.IPayPrestoreService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * 费用预存管理Controller
 * 
 * @author yy
 * @date 2023-10-27
 */
@RestController
@RequestMapping("/pay/prestore")
public class PayPrestoreController extends BaseController
{
    @Autowired
    private IPayPrestoreService payPrestoreService;

    /**
     * 查询费用预存管理列表
     */
    @PreAuthorize("@ss.hasPermi('pay:prestore:list')")
    @GetMapping("/list")
    public TableDataInfo list(PayPrestore payPrestore)
    {
        startPage();
        List<PayPrestore> list = payPrestoreService.selectPayPrestoreList(payPrestore);
        return getDataTable(list);
    }

    /**
     * 导出费用预存管理列表
     */
    @PreAuthorize("@ss.hasPermi('pay:prestore:export')")
    @Log(title = "费用预存管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PayPrestore payPrestore)
    {
        List<PayPrestore> list = payPrestoreService.selectPayPrestoreList(payPrestore);
        ExcelUtil<PayPrestore> util = new ExcelUtil<PayPrestore>(PayPrestore.class);
        util.exportExcel(response, list, "费用预存管理数据");
    }

    /**
     * 获取费用预存管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('pay:prestore:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(payPrestoreService.selectPayPrestoreById(id));
    }

    /**
     * 新增费用预存管理
     */
    @PreAuthorize("@ss.hasPermi('pay:prestore:add')")
    @Log(title = "费用预存管理", businessType = BusinessType.INSERT)
    @PostMapping("addPay")
    public AjaxResult addPay(@RequestBody PayPrestore payPrestore)
    {
        return toAjax(payPrestoreService.insertPayPrestorePay(payPrestore));
    }

    /**
     * 确定收费
     */
    @PreAuthorize("@ss.hasPermi('pay:prestore:confirm')")
    @Log(title = "费用预存确定收费", businessType = BusinessType.UPDATE)
    @PostMapping("confirmPay/{id}")
    public AjaxResult confirmPay(@PathVariable Long id)
    {
        return toAjax(payPrestoreService.confirmPay(id));
    }

    /**
     * 根据业主ID查询当前业主的所有预存款
     */
    @PreAuthorize("@ss.hasPermi('pay:prestore:add')")
    @GetMapping("getPayPrestoreAccountByUserOwnerId/{id}")
    public AjaxResult getPayPrestoreAccountByUserOwnerId(@PathVariable Long id)
    {
        PayPrestoreAccount account=this.payPrestoreService.queryPayPrestoreAccountByUserOwnerId(id);
        return AjaxResult.success(account);
    }

    /**
     * 新增费用预存[退费]
     */
    @PreAuthorize("@ss.hasPermi('pay:prestore:add')")
    @Log(title = "预存", businessType = BusinessType.INSERT)
    @PostMapping("addRefund")
    public AjaxResult addRefund(@RequestBody PayPrestore payPrestore)
    {
        return this.toAjax(this.payPrestoreService.addRefund(payPrestore));
    }

    /**
     * 费用退还确定
     * @param id
     * @return
     */
    @PreAuthorize("@ss.hasPermi('pay:prestore:add')")
    @Log(title = "费用预存确定", businessType = BusinessType.INSERT)
    @PostMapping("confirmRefund/{id}")
    public AjaxResult confirmRefund(@PathVariable Long id)
    {
        return toAjax(this.payPrestoreService.confirmRefund(id));
    }



}
